<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="报告初审">
    <!--suppress ALL -->
     <form id="searchForm" class="form-panel" action="${basepath}">
         <ul class="panel-content">
             <li>
                 <div class="form-actions">
                     <div class="control-group controls span5">
                         <input type="text" class="input-normal  input-pad" name="name"
                                placeholder="请输入关键字搜索">
                     </div>
                     <div class="control-group controls span8">
                         <label class="time-label control-label" style="line-height: 40px;">请选择状态：</label>
                         <select name="status" class="input-normal" id="status">
                             <option value="">请选择状态</option>
                             <option value="编写报告">编写报告</option>
                             <option value="一审中">一审中</option>
                             <option value="二审中">二审中</option>
                             <option value="发放打印">发放打印</option>
                             <option value="已完成">已完成</option>
                         </select>

                     </div>
                     <button type="submit" class="button  button-primary">
                         查询
                     </button>

                 </div>
             </li>
         </ul>
     </form>
<#----------------------------------------------指派人员表单start--------------------------------------------------------->
<div id="addPeopleContent" style="display:none;">
    <form id="addPeopleForm" class="form-horizontal"
          action="${basepath}/rest/manage/handlelog/insertFirstReportHandleLog" method="post">
        <input type="hidden" class="input-normal control-text" name="proxyID" id="appointID"/>
        <input type="hidden" class="input-normal control-text" name="status" id="appointStatus"/>
        <div class="row">
            <div class="control-group" id="actionName-group">
                <label class="control-label" style="width: 130px;">
                    执行动作：
                </label>
                <div class="controls bui-form-group-select">
                    <select class="span7" name="actionName" id="actionPeopleName">
                        <option value="">请选择执行动作</option>
                        <option value="提交">提交</option>
                        <option value="回退">回退</option>
                    </select>
                </div>
            </div>
            <div id="assigned-people">
                <div class="control-group span16">
                    <label class="control-label" style="width: 120px;">
                        是否已通过一审：
                    </label>
                    <div class="controls bui-form-group-select">
                        <select class="span7 actionFirst" name="isSecond">
                            <option value="">请选择是否已通过一审</option>
                            <option value="y">是</option>
                            <option value="n">否</option>
                        </select>
                    </div>
                </div>
                <div class="first-people">
                    <label class="control-label censorPeople" style="width: 130px;">
                        一审人员：
                    </label>
                    <div class="controls bui-form-group-select">
                        <div id="send-first" class="people">
                            <input type="hidden" id="send-peopleFirst" name="userID">
                        </div>
                    </div>
                </div>
            </div>
            <div class="control-group span16">
                <label class="control-label" style="width: 120px;">
                    留言备注：
                </label>
                <div class="controls  control-row-auto " style="margin-left: 0px;">
                    <textarea name="remark" placeholder="请输入内容" class="span7"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------指派人员表单 end---------------------------------------------------------->


<div id="grid"></div>
<script>
    //查询登陆用户的名称
    var userID = "", isHeadman = "";
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/manage/user/selectLoginUser',
        success: function (data) {
            userID = data.data.id;
            isHeadman = data.data.isHeadman;
            query();
        }
    })
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            Select = BUI.Select, columns = "", store = "", grid = "";

    function query() {
        columns = [
            {
                title: '序号',
                elCls: 'center',
                dataIndex: 'id',
                width: '10%',
                renderer: function (value, obj, index) {
                    return index + 1;
                }
            },

            {
                title: '委托书名称', dataIndex: 'name', elCls: 'center', width: '15%', renderer: function (value, obj) {
                    return '<a href="${basepath}/rest/manage/proxy/toProxyDetail?id=' + obj.id + '">' + value + '</a>';
                }
            },
            {title: '委托书编号', dataIndex: 'sno', elCls: 'center', width: '10%'},
            {title: '收到时间', dataIndex: 'updateTime', elCls: 'center', width: '15%'},
            {
                title: '事件跟踪', dataIndex: 'id', elCls: 'center', width: '10%', renderer: function (value) {
                    return '<a href="${basepath}/rest/manage/proxy/toEventList?proxyID=' + value + '">查看</a>';
                }
            },
            {
                title: '当前状态',
                dataIndex: 'status',
                elCls: 'center',
                width: '15%',
                renderer: function (value) {
                    switch (value) {
                        case '等待提交委托书':
                            return '等待提交委托书';
                            break;
                        case '等待指派采样人员':
                            return '等待指派采样人员';
                            break;
                        case '采样中':
                            return '采样中';
                            break;
                        case '等待指派实验人员':
                            return '等待指派实验人员';
                            break;
                        case '实验分析':
                            return '实验分析';
                            break;
                        case '编写报告':
                            return '编写报告';
                            break;
                        case '一审中':
                            return '一审中';
                            break;
                        case '二审中':
                            return '二审中';
                            break;
                        case '发放打印':
                            return '发放打印';
                            break;
                        case '已完成':
                            return '已完成';
                            break;
                    }
                }
            },
            {
                title: '留言备注', dataIndex: 'remark', elCls: 'center', width: '15%', renderer: function (value) {
                    return value == "" || value == null ? "____" : value;
                }
            },
            {
                title: '操作', elCls: 'center', dataIndex: 'id', width: '10%', renderer: function (value, obj) {
                    return obj.status == '编写报告' ? '<a href="javascript:operating(' + value + ',\'' + obj.status + '\')">操作</a>' : "____";
                }
            }
        ];
        var url = "";
        isHeadman == 'n' ? url = '/rest/manage/proxy/selectFirstReportProxyPage?userID=' + userID + '' : url = '/rest/manage/proxy/selectFirstReportProxyPage'
        store = new Store({
            url: url,
            autoLoad: true, //自动加载数据
            params: { //配置初始请求的参数
                length: '10',
                status: $("#status").val()
            },
            pageSize: 10,	// 配置分页数目
            root: 'list',
            totalProperty: 'total'
        });
        grid = new Grid.Grid({
            render: '#grid',
            columns: columns,
            loadMask: true, //加载数据时显示屏蔽层
            store: store,
            plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
            // 底部工具栏
            bbar: {
                pagingBar: true
            }
        });
        grid.render();
    }

    /**********************模糊搜索*************************/
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });

    /*********************************指派人员的操作***********************************/
    function operating(id, status) {
        addPeopleForm.clearFields();
        addPeopleDialog.show();
        $("#appointID").val(id);
        $("#appointStatus").val(status);
        queryFirstPeople()
    }

    $("#actionPeopleName").change(function () {
        var type = $(this).val(), html = "";
        if (type == '提交') {
            $("#assigned-people").remove();
            html = '<div id="assigned-people"><div class="control-group span16"><label class="control-label" style="width:120px;">是否已通过一审： </label>' +
                    '<div class="controls bui-form-group-select"><select class="span7 actionFirst" name="isSecond"  data-rules="{required : true}"><option value="">请选择是否已通过一审</option> <option value="y">是</option> <option value="n">否</option></select>' +
                    '</div></div><div class="first-people"> <label class="control-label censorPeople" style="width:130px;">一审人员：</label>' +
                    '<div class="controls bui-form-group-select"><div id="send-first" class="people"><input type="hidden" id="send-peopleFirst" name="userID"> </div> </div> </div> </div>';
            $("#actionName-group").after(html);
            queryFirstPeople();
            //是否已通过一审，是的情况出现二审人员，不是情况下出现选择一审人员
            $(".actionFirst").change(function () {
                $("#send-first .bui-select").remove();
                $(this).val() == 'y' ? $(".censorPeople").html('二审人员') && querySecondPeople() : $(".censorPeople").html('一审人员') && queryFirstPeople();
            })
        } else {
            $("#assigned-people").remove();
        }
    })

    var addPeopleForm = new BUI.Form.Form({
        srcNode: '#addPeopleForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addPeopleDialog.close();
        }
    }).render();

    var addPeopleDialog = new BUI.Overlay.Dialog({
        title: '操作',
        width: 560,
        height: 350,
        contentId: 'addPeopleContent',
        success: function () {
            if (addPeopleForm.isValid()) {
                addPeopleForm.submit();
            } else {
                addPeopleForm.valid();
            }
        }
    });

    /*********************************查询一审指派人员的多选框查询人员***********************************/
    function queryFirstPeople() {
        var pStore = new Store({
            url: '${basepath}/rest/manage/user/selectAllList?role_name=报告组长&isHeadman=n',
            autoLoad: true,
            root: 'data',
        });
        var pSelect = new Select.Select({
            render: '#send-first',
            valueField: '#send-peopleFirst',
            list: {
                itemTpl: '<li class="bui-list-item"><span class="x-checkbox"></span>{nickname}</li>',
                idField: 'id'
            },
            multipleSelect: true,
            store: pStore
        }).render();
    }

    /*********************************查询二审指派人员的多选框查询人员***********************************/
    function querySecondPeople() {
        var pStore = new Store({
            url: '${basepath}/rest/manage/user/selectAllList?role_name=报告终审&isHeadman=n',
            autoLoad: true,
            root: 'data',
        });
        var pSelect = new Select.Select({
            render: '#send-first',
            valueField: '#send-peopleFirst',
            list: {
                itemTpl: '<li class="bui-list-item"><span class="x-checkbox"></span>{nickname}</li>',
                idField: 'id'
            },
            multipleSelect: true,
            store: pStore
        }).render();
    }

</script>

</@page.pageBase>
